//
//  UserView.m
//  暴走段子_王桂敏
//
//  Created by 王桂敏 on 15/6/8.
//  Copyright (c) 2015年 lanouhn. All rights reserved.
//

#import "UserView.h"
#import "UIImageView+WebCache.h"
#import "Define.h"
@implementation UserView

- (void)dealloc{
    [_icon release];
    [_login release];
    [_age release];
    [_astrology release];
    [_hometown release];
    [_qb_age release];
    [_mobile_brand release];
    [_job release];
    [_haunt release];
    [_big_cover release];
    [super dealloc];
}
- (UIImageView *)big_cover{
    if (!_big_cover) {
        self.big_cover = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 64, kSCREENWIDTH, kSCREENHEIGHT - 64)] autorelease];
        [self addSubview:_big_cover];
    }
    return _big_cover;
}
- (UIImageView *)icon{
    if (!_icon) {
        self.icon = [[[UIImageView alloc] initWithFrame:CGRectMake(20, 80, 40, 40)] autorelease];
        _icon.layer.cornerRadius = 20;
        _icon.layer.masksToBounds = YES;
        _icon.layer.borderColor = [UIColor whiteColor].CGColor;
        _icon.layer.borderWidth = 2;
        [self addSubview:_icon];
    }
    return _icon;
}
- (UILabel *)login{
    if (!_login) {
        self.login = [[[UILabel alloc] initWithFrame:CGRectMake(65, 80, 150, 20)] autorelease];
        _login.font = [UIFont systemFontOfSize:15];
        _login.textColor = [UIColor whiteColor];
        [self addSubview:_login];
    }
    return _login;
}
- (UILabel *)age{
    if (!_age) {
        self.age = [[[UILabel alloc] initWithFrame:CGRectMake(65, 100, 30, 15)] autorelease];
        _age.backgroundColor = [UIColor colorWithRed:135 / 256.0 green:206 / 256.0 blue:250 / 256.0 alpha:1];
        _age.layer.cornerRadius = 2;
        _age.layer.masksToBounds = YES;
        _age.font = [UIFont systemFontOfSize:10];
        _age.textColor = [UIColor whiteColor];
        _age.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_age];
    }
    return _age;
}
- (UILabel *)astrology{
    if (!_astrology) {
        self.astrology = [[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 40, 15)] autorelease];
        _astrology.backgroundColor = [UIColor colorWithRed:135 / 256.0 green:206 / 256.0 blue:250 / 256.0 alpha:1];
        _astrology.layer.cornerRadius = 2;
        _astrology.layer.masksToBounds = YES;
        _astrology.font = [UIFont systemFontOfSize:10];
        _astrology.textColor = [UIColor whiteColor];
        _astrology.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_astrology];
    }
    return _astrology;
}
- (UILabel *)haunt{
    if (!_haunt) {
        self.haunt = [[[UILabel alloc] initWithFrame:CGRectMake((kSCREENWIDTH - 230) / 2, kSCREENHEIGHT - 200, 100, 20)] autorelease];
        _haunt.layer.cornerRadius = 10;
        _haunt.layer.masksToBounds = YES;
        _haunt.layer.borderColor = [UIColor whiteColor].CGColor;
        _haunt.layer.borderWidth = 1;
        _haunt.textAlignment = NSTextAlignmentCenter;
        _haunt.textColor = [UIColor whiteColor];
        _haunt.font = [UIFont systemFontOfSize:12];
        [self addSubview:_haunt];
    }
    return _haunt;
}
- (UILabel *)qb_age{
    if (!_qb_age) {
        self.qb_age = [[[UILabel alloc] initWithFrame:CGRectMake((kSCREENWIDTH - 230) / 2 + 105, kSCREENHEIGHT - 200, 50, 20)] autorelease];
        _qb_age.layer.cornerRadius = 10;
        _qb_age.layer.masksToBounds = YES;
        _qb_age.layer.borderWidth = 1;
        _qb_age.layer.borderColor = [UIColor whiteColor].CGColor;
        _qb_age.textColor = [UIColor whiteColor];
        _qb_age.textAlignment = NSTextAlignmentCenter;
        _qb_age.font = [UIFont systemFontOfSize:12];
        [self addSubview:_qb_age];
    }
    return _qb_age;
}
- (UILabel *)mobile_brand{
    if (!_mobile_brand) {
        self.mobile_brand = [[[UILabel alloc] initWithFrame:CGRectMake((kSCREENWIDTH - 230) / 2 + 105 + 55, kSCREENHEIGHT - 200, 80, 20)] autorelease];
        _mobile_brand.layer.cornerRadius = 10;
        _mobile_brand.layer.masksToBounds = YES;
        _mobile_brand.layer.borderColor = [UIColor whiteColor].CGColor;
        _mobile_brand.layer.borderWidth = 1;
        _mobile_brand.textAlignment = NSTextAlignmentCenter;
        _mobile_brand.textColor = [UIColor whiteColor];
        _mobile_brand.font = [UIFont systemFontOfSize:12];
        [self addSubview:_mobile_brand];
    }
    return _mobile_brand;
}
- (UILabel *)job{
    if (!_job) {
        self.job = [[[UILabel alloc] initWithFrame:CGRectMake((kSCREENWIDTH - 155) / 2, kSCREENHEIGHT - 200 + 10 + 20, 50, 20)] autorelease];
        _job.layer.masksToBounds = YES;
        _job.layer.cornerRadius = 10;
        _job.layer.borderWidth = 1;
        _job.layer.borderColor = [UIColor whiteColor].CGColor;
        _job.textAlignment = NSTextAlignmentCenter;
        _job.textColor = [UIColor whiteColor];
        _job.font = [UIFont systemFontOfSize:12];
        [self addSubview:_job];
    }
    return _job;
}
- (UILabel *)hometown{
    if (!_hometown) {
        self.hometown = [[[UILabel alloc] initWithFrame:CGRectMake((kSCREENWIDTH - 155) / 2 + 50 + 5, kSCREENHEIGHT - 200 + 10 + 20, 100, 20)] autorelease];
        _hometown.layer.masksToBounds = YES;
        _hometown.layer.cornerRadius = 10;
        _hometown.layer.borderColor = [UIColor whiteColor].CGColor;
        _hometown.layer.borderWidth = 1;
        _hometown.textAlignment = NSTextAlignmentCenter;
        _hometown.textColor = [UIColor whiteColor];
        _hometown.font = [UIFont systemFontOfSize:12];
        [self addSubview:_hometown];
    }
    return _hometown;
}

- (void)_configUserWithUser:(UserModel *)user{
//------------用户自定义背景图片-----------
    if (user.big_cover.length == 0) {
        self.big_cover.image = [UIImage imageNamed:@"anyUser.jpg"];
    } else {
        [self.big_cover sd_setImageWithURL:[NSURL URLWithString:user.big_cover] placeholderImage:[UIImage imageNamed:@"anyUser.jpg"]];
    }
//---------------用户头像-----------------
    NSString *userUidStr = [NSString stringWithFormat:@"%@",user.uid];
    if ([user.icon isKindOfClass:[NSNull class]]) {
        self.icon.image = [UIImage imageNamed:@"user_icon_anonymous"];
    } else {
        [self.icon sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://pic.qiushibaike.com/system/avtnew/%@/%@/medium/%@",[userUidStr substringWithRange:NSMakeRange(0, 4)],userUidStr,user.icon]] placeholderImage:[UIImage imageNamed:@"user_icon_anonymous"]];
    }
//----------------用户名-----------------
    if (user.login.length == 0) {
        self.login.text = @"未知";
    } else {
        self.login.text = user.login;
    }
//-----------------年龄------------------
    if (user.age.stringValue.length == 0) {
        self.age.text = @"未知";
    } else {
        self.age.text = [NSString stringWithFormat:@"%@岁",user.age.stringValue];
    }
//-----------------星座------------------
    if (user.astrology.length == 0) {
        self.astrology.text = @"未知";
    } else {
        self.astrology.text = user.astrology;
    }
//-----------------所在地-----------------
    if (user.haunt.length == 0) {
        self.haunt.text = @"未知";
    } else {
        self.haunt.text = user.haunt;
    }
//-----------------糗百年龄---------------
    if (user.qb_age.stringValue.length == 0) {
        self.qb_age.text = @"未知";
    } else {
        self.qb_age.text = user.qb_age.stringValue;
    }
//-----------------使用设备---------------
    if (user.mobile_brand.length == 0) {
        self.mobile_brand.text = @"未知";
    } else {
        self.mobile_brand.text = user.mobile_brand;
    }
//-----------------职业-------------------
    if (user.job.length == 0) {
        self.job.text = @"未知";
    } else {
        self.job.text = user.job;
    }
//------------------家乡------------------
    if (user.hometown.length == 0) {
        self.hometown.text = @"未知";
    } else {
        self.hometown.text = user.hometown;
    }
}

@end
